
public class GaussianLeftStepMembershipFunction extends MembershipFunction {

	private static final int NUM_STD_DEVS = 3;	// # of std. deviations to sample
	
	public GaussianLeftStepMembershipFunction(double mean, double sigma) {
		lowerBound = mean - sigma * NUM_STD_DEVS;
		sampledValues = new double[(int)(sigma * NUM_STD_DEVS * 2 / RESOLUTION) + 1];
		for (int i = 0; i < sampledValues.length; i++) {
			double x = lowerBound + i * RESOLUTION;
			if (x > mean)
				sampledValues[i] = Math.exp(-0.5 * Math.pow((x - mean) / sigma, 2));
			else
				sampledValues[i] = 1;
		}
	}
	
	public double getValue(double x) {
		int index = (int)((x - lowerBound) / RESOLUTION);
		if (index >= 0 && index < sampledValues.length && x >= lowerBound)
			return sampledValues[index];
		else if (x < lowerBound) 
			return 1;
		return 0;
	}
}
